package com.zhizuobiao.coura.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhizuobiao.coura.stockhelper.R;
import com.zhizuobiao.coura.utils.DateUtil;
import com.zhizuobiao.coura.utils.WeatherUtil;
import com.zhizuobiao.coura.weather.Weather;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by coura on 2016/12/23.
 */

public class WeatherListAdapter extends BaseAdapter {

    private Context context;
    private List<Weather.ResultsBean.WeatherDataBean> list;

    public WeatherListAdapter(Context context, List<Weather.ResultsBean.WeatherDataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.weather_listview, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        String weather = list.get(position).getWeather();
        if (position == 0){
            holder.tvListTime.setText(DateUtil.getCurWeek());
        }else {
            holder.tvListTime.setText(list.get(position).getDate());
        }
        holder.ivListWeatherPic.setImageResource(WeatherUtil.getWeatherIcon(weather));
        holder.tvListWeather.setText(weather);
        holder.tvListTemperature.setText(list.get(position).getTemperature());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.tv_list_time)
        TextView tvListTime;
        @BindView(R.id.iv_list_weatherPic)
        ImageView ivListWeatherPic;
        @BindView(R.id.tv_list_weather)
        TextView tvListWeather;
        @BindView(R.id.tv_list_temperature)
        TextView tvListTemperature;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
